#include "whip.h"
#include "Listtexture.h";
#include "Global.h"
whip::whip(void){}
whip::~whip(void){}
void whip::Init()
{
	sprite = new Sprite(Listtexture::WHIP,Listtexture::WHIP_WIDTH,Listtexture::WHIP_HEIGHT,
		Listtexture::WHIP_COUNT,Listtexture::WHIP_SPRITEPERROW);
	isFight = false;
	count = 0;
	animateRate = Listtexture::WHIP_ANIMATE;
	lastAnimate = GetTickCount();
}

void whip::setDirection(int t, int left, int top)
{
	if (t == 0) //ben trai
	{
		
		isFight=true;
		
		sprite->Next(Listtexture::WHIP_LEFT_START,Listtexture::WHIP_LEFT_END+1);
		if (sprite->_index  == 3)
		{
			isFight = false;
		}

		
		if( sprite->_index == 0)
		{
			UpdateRect(left+20,top-20,width,height);
		}
		if(sprite->_index == 1)
		{
			UpdateRect(left+20,top,width,height);
		}
		if( sprite->_index == 2)
		{
			UpdateRect(left-80,top,width,height);
		}

		
	}
	else if(t == 1) //ben phai
	{
		
		isFight=true;
		
		sprite->Next(Listtexture::WHIP_RIGHT_START,Listtexture::WHIP_RIGHT_END+1);
		if (sprite->_index == 6)
		{
			isFight = false;
		}
		if( sprite->_index == 3)
		{
			UpdateRect(left-40,top-20,width,height);
		}
		if(sprite->_index == 4)
		{
			UpdateRect(left-40,top,width,height);
		}
		if( sprite->_index == 5)
		{
			UpdateRect(left+60,top,width,height);
		}
	}
}
void whip::updateRect(int left , int top)
{
	UpdateRect(left,top,width,height);
}
void whip::render()
{
	RECT screen = Global::Screen;
	if (isFight)
	{
		sprite->Render(backbuffer,rectDraw.left,rectDraw.top,screen.left,screen.bottom);
	}
}